package com.stefanini.pe.bbva.mbl.in.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.stefanini.pe.bbva.mbl.carga.in.to.Corporativa;
import com.stefanini.pe.bbva.mbl.carga.in.to.CorporativaKey;
import com.stefanini.pe.bbva.mbl.in.dao.iface.CorporativaDAO;

public class CorporativaDAODualImpl extends SqlMapClientDaoSupport implements CorporativaDAO {


	
	
	 
	private Map<String, SqlMapClientTemplate> commandMap;
	
    public Map<String, SqlMapClientTemplate> getCommandMap() {
		return commandMap;
	}

	public void setCommandMap(Map<String, SqlMapClientTemplate> commandMap) {
		this.commandMap = commandMap;
	}

	private SqlMapClientTemplate getSqlMapClientTemplate2(String schema) throws Exception {
		
		return commandMap.get(schema);
				
	}
	
	
	
	/**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table IIPG.TIIPG_CORPORATIVA
     *
     * @ibatorgenerated Tue Apr 13 21:46:35 COT 2010
     */
    public CorporativaDAODualImpl() {
        //super();
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table IIPG.TIIPG_CORPORATIVA
     *
     * @ibatorgenerated Tue Apr 13 21:46:35 COT 2010
     */
    public int deleteByPrimaryKey(CorporativaKey key) {
        int rows = getSqlMapClientTemplate().delete("IIPG_TIIPG_CORPORATIVA.ibatorgenerated_deleteByPrimaryKey", key);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table IIPG.TIIPG_CORPORATIVA
     *
     * @ibatorgenerated Tue Apr 13 21:46:35 COT 2010
     */
    public void insert(Corporativa record) {
        getSqlMapClientTemplate().insert("IIPG_TIIPG_CORPORATIVA.ibatorgenerated_insert", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table IIPG.TIIPG_CORPORATIVA
     *
     * @ibatorgenerated Tue Apr 13 21:46:35 COT 2010
     */
    public void insertSelective(Corporativa record) {
        getSqlMapClientTemplate().insert("IIPG_TIIPG_CORPORATIVA.ibatorgenerated_insertSelective", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table IIPG.TIIPG_CORPORATIVA
     *
     * @ibatorgenerated Tue Apr 13 21:46:35 COT 2010
     */
    public Corporativa selectByPrimaryKey(CorporativaKey key) {
        Corporativa record = (Corporativa) getSqlMapClientTemplate().queryForObject("IIPG_TIIPG_CORPORATIVA.ibatorgenerated_selectByPrimaryKey", key);
        return record;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table IIPG.TIIPG_CORPORATIVA
     *
     * @ibatorgenerated Tue Apr 13 21:46:35 COT 2010
     */
    public int updateByPrimaryKeySelective(Corporativa record) {
        int rows = getSqlMapClientTemplate().update("IIPG_TIIPG_CORPORATIVA.ibatorgenerated_updateByPrimaryKeySelective", record);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table IIPG.TIIPG_CORPORATIVA
     *
     * @ibatorgenerated Tue Apr 13 21:46:35 COT 2010
     */
    public int updateByPrimaryKey(Corporativa record) {
        int rows = getSqlMapClientTemplate().update("IIPG_TIIPG_CORPORATIVA.ibatorgenerated_updateByPrimaryKey", record);
        return rows;
    }
    
    public List selectByCriteria(Corporativa record){
    	List records = (List) getSqlMapClientTemplate().queryForList(
				"IIPG_TIIPG_CORPORATIVA.ibatorgenerated_selectByCriteria",record);
		return records;
    }
    
    public List selectByCriteriaLit_Lar(Corporativa record){
    	List records= new ArrayList(); 
    	try {
    	records = (List) getSqlMapClientTemplate2(record.getSchemaActivo()).queryForList(
				"IIPG_TIIPG_CORPORATIVA.ibatorgenerated_selectByCriteriaLit_Lar",record);
    	
    	}catch (Exception e) {
			// TODO: handle exception
		}
		return records;
    }
    
    
    
    
    
    public List selectTabs() {
    	List records = (List) getSqlMapClientTemplate().queryForList("IIPG_TIIPG_CORPORATIVA.ibatorgenerated_selectTabs");
    	return records;
    }

    public List selectByTab(Corporativa record) {
    	
    	List records= new ArrayList(); 
    	try {
    		records = (List) getSqlMapClientTemplate2(record.getSchemaActivo()).queryForList("IIPG_TIIPG_CORPORATIVA.ibatorgenerated_selectByTab", record);	
		} catch (Exception e) {
			System.out.println("Exception devolviendo sqlmapclientetemplate2:"+e.getMessage());
			// TODO: handle exception
		}
    	
    	
    	return records;
    }
    
    public List selectMaxElemByTab(Corporativa record) {
    	List records = (List) getSqlMapClientTemplate().queryForList("IIPG_TIIPG_CORPORATIVA.ibatorgenerated_selectMaxElemByTab", record);
    	return records;
    }
    
    public String actualizarNombreDirectorio(String nomDirAnt, String nomDirNuevo) {
		HashMap map = new HashMap();
		String retorno = null;

		logger.info("Inicio");
		
		map.put("pi_nom_dir_ant", nomDirAnt);
		map.put("pi_nom_dir_nuevo", nomDirNuevo);

		this.getSqlMapClientTemplate().queryForObject("CORPORATIVA.sp_renombra_directorio", map);

		logger.info("Fin");

		return retorno;
	}
}